home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / UNSPLIT / text0339.txt < prev    next >
Encoding:
Text File  |  1997-02-06  |  1.0 KB  |  37 lines

  1. On Tue, 4 Jun 1996, Anthony Jacques wrote:
  2.  
  3. > just a quicky... one of the functions that the DEU source code takes a string,
  4. > and some parameters in the same way as printf (but with an extra one at the
  5. > beginning). I want to take these parameters, and combine them into a single
  6. > string (using sprintf) but I dont have any idea how to do this...
  7.  
  8. Use vsprintf. That's what it's made for. I include a piece of code from a 
  9. server I've written (it's the logging function, supports things like:
  10. (the real version doesnt use vsprintf anymore because of the risk of 
  11. buffer overruns, but that's besides the point)
  12.  
  13. log2( LOG_ERROR, "File: %s not found, line: %d", filename, line );
  14.  
  15. Here is the code (rehacked for ease of reading):
  16.  
  17. --------- cut here ------------
  18. void log2( int level, char *format, ... )
  19. {
  20.   va_list l;
  21.   char str[ 10240 ];
  22.  
  23.   va_start( l, format );
  24.   if( config.debug_level >= level ) {
  25.     vsprintf( str, format, l );
  26.     save_line_to_file( str, "debug.log" );
  27.   }
  28.   va_end( l );
  29. }
  30. ----------- cut here ------------
  31.  
  32.  
  33. -- 
  34. Elias Martenson
  35. elias@omicron.se
  36.  
  37.